<!--
 - MineAdmin is committed to providing solutions for quickly building web applications
 - Please view the LICENSE file that was distributed with this source code,
 - For the full copyright and license information.
 - Thank you very much for using MineAdmin.
 -
 - @Author X.Mo<root@imoi.cn>
 - @Link   https://gitee.com/xmo/mineadmin-vue
-->
<template>
  <a-modal width="800px" v-model:visible="visible" :on-before-ok="save" :onClose="closeData" unmount-on-close>
    <template #title>
      修改配置：{{ changeName }}
    </template>

    <a-form :model="form" ref="formRef">
      <a-form-item field="app_id" label="商户号 mch_id" required>
        <a-input v-model="form.mch_id" placeholder=" 必填-商户号"
                 allow-clear mode="button"/>

      </a-form-item>

      <a-form-item field="mch_cert_path" label="商户公私钥" required>
        <a-input v-model="form.mch_cert_path" placeholder="必填-商户公私钥"
                 allow-clear mode="button"/>
      </a-form-item>


      <a-form-item field="mch_cert_password" label="商户公私钥密码" required>
        <a-input v-model="form.mch_cert_password" placeholder="必填-商户公私钥密码"
                 allow-clear mode="button"/>

      </a-form-item>
      <a-form-item field="unipay_public_cert_path" label="银联公钥证书路径" required>
        <a-input v-model="form.unipay_public_cert_path" placeholder="必填-银联公钥证书路径"
                 allow-clear mode="button"/>
      </a-form-item>


      <a-form-item field="return_url" label="支付后,返回路径" required>
        <a-input v-model="form.return_url" placeholder="支付后,返回路径"
                 allow-clear mode="button"/>
      </a-form-item>

      <a-form-item field="notify_url" label="必填-回调路径" required>
        <a-input v-model="form.notify_url" placeholder="必填-回调路径"
                 allow-clear mode="button"/>
      </a-form-item>


    </a-form>
  </a-modal>
</template>

<script setup>
import {onMounted, reactive, ref} from 'vue'
import {Message} from '@arco-design/web-vue'
import paymentMethod from '@/api/payment/paymentMethod'


const visible = ref(false)

const form = ref({})
const formRef = ref()
const changeName = ref();
const emit = defineEmits(['success'])

const open = async (record) => {
  changeName.value = record.channel_name
  form.value.id=record.id;
  var settings=record.setting
  form.value.mch_id=settings.mch_id;
  form.value.mch_cert_path=settings.mch_cert_path;
  form.value.mch_cert_password=settings.mch_cert_password;
  form.value.unipay_public_cert_path=settings.unipay_public_cert_path;
  form.value.return_url=settings.return_url;
  form.value.notify_url=settings.notify_url;
  visible.value = true
}
//----选择框变化


const save = async (done) => {
  console.log(form.value);
  const response = await paymentMethod.saveConfig(form.value);
  response.success && Message.success(response.message);
  formRef.value.resetFields();
  emit('success')
  done(true)
}
const closeData = () => {

  formRef.value.resetFields();
}


defineExpose({open})
</script>

<style scoped>
.copy-button {
  position: absolute;
  right: 15px;
  top: 0px;
  z-index: 999;
}
</style>